package 柱状图中最大的矩形harder;

public class Solution1 {

    //方法一：暴力解法
    public int largestRectangleArea(int[] heights) {

        //定义一个变量获取数组的长度
        int len = heights.length;
        int res = 0;
        //判断极端情况
        if(len == 0){
            return 0;
        }

        //开始循环遍历每个元素
        for (int i = 0; i < len; i++) {
            int left = i;
            int currentHeight = heights[i];
            while(left >0 && heights[left-1] >= currentHeight){
                left--;
            }
            int right = i;
            while (right < len-1 && heights[right+1] >= currentHeight){
                right++;
            }

            int width = right -left + 1;
            res = Math.max(res,width * currentHeight);
        }
        return  res;
    }



}
